package serviceimpl;

import Tool.ToolInter;
import bean.Students;
import dao.StudentsDaoInter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import service.StudentsServiceInter;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by Administrator on 2017/4/25.
 */
public class StudentsServiceImpl implements StudentsServiceInter {
    private StudentsDaoInter studentsDaoImpl;
    private ToolInter ToolImpl;

    public StudentsDaoInter getStudentsDaoImpl() {
        return studentsDaoImpl;
    }

    public void setStudentsDaoImpl(StudentsDaoInter studentsDaoImpl) {
        this.studentsDaoImpl = studentsDaoImpl;
    }

    public ToolInter getToolImpl() {
        return ToolImpl;
    }

    public void setToolImpl(ToolInter toolImpl) {
        ToolImpl = toolImpl;
    }

    @Override
    public String queryAllStudents() {

        List<Students> students = this.getStudentsDaoImpl().queryAll();
        JSONArray jsonArray = new JSONArray();
        JSONObject obj = new JSONObject();
        JSONArray practiceReport = new JSONArray();
        for (int i = 0; i < students.size(); i++) {
            LinkedHashMap report = new LinkedHashMap();
            try {

                report.put("sId", students.get(i).getSid());

                report.put("sName", students.get(i).getSname());

                report.put("sSex", students.get(i).getSsex());

                report.put("sMajor", students.get(i).getSmajor());

                report.put("sSession", students.get(i).getSsession());
                report.put("sResearch", students.get(i).getSresearch());


                report.put("sPaper", students.get(i).getSpaper());
                report.put("sPatent", students.get(i).getSpatent());
                report.put("SPaper", students.get(i).getSpaper());
                report.put("sSfot", students.get(i).getSsoft());
                report.put("sReward", students.get(i).getSreward());


                JSONObject json = JSONObject.fromObject(report);

                practiceReport.add(json);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        obj.put("data", practiceReport);
        jsonArray.add(obj);
        return jsonArray.toString();
    }
}